
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	String username=request.getParameter("username");
	String password=request.getParameter("password");
	String confimpassword=request.getParameter("confirmPassword"); //修改的密码
%>
<%
	try{
		//连接数据库
				String driverName="com.mysql.jdbc.Driver";
				String url="jdbc:mysql://localhost:3306/hotel";
				String userName="root";
				String passWord="root";
				
				Class.forName(driverName);
				Connection con=DriverManager.getConnection(url,userName,passWord);
				String sql="select * from adinfo where adname=? and adpwd=? ;";
				PreparedStatement pstat=con.prepareStatement(sql);
				pstat.setString(1, username);
				pstat.setString(2, password);
				ResultSet rs=pstat.executeQuery(); //执行查询
				if(rs.next()){ //如果账号跟密码存在,则可以修改密码
					String aName=rs.getString("adname");
					String aPass=rs.getString("adpwd");
					out.print("登录成功");
					Connection con2=DriverManager.getConnection(url,userName,passWord);
					String sql2="update  adinfo set adpwd=? where adname=? ;";
					PreparedStatement pstat2=con.prepareStatement(sql2);
					pstat2.setString(1, confimpassword);
					pstat2.setString(2, username);
					int num=pstat2.executeUpdate();
					if(num!=0){
						response.sendRedirect("login.jsp");
					}else{
						out.print("修改密码失败");
						out.print("<a href='change.jsp'>返回</a>");
					}
					
					
				}else{
					if(username==""||password==""){
						out.print("账号和密码不能有空");
					}else{
						out.println("用户名或者密码不正确");
					}
					
				}
					
				
				if (con != null && !con.isClosed()) {
			        con.close();
			      }
				
	}catch(Exception e){
		e.printStackTrace();
	}
%>
</body>
</html>